capture log close
log using ReplicationFile_Tables_Figures, replace text

// Master-file to reproduce all figures and tables for "Immigration, Integration and Cooperation: Experimental Evidence from a Public Goods Game in Italy"
// Author: Johanna Gereke 
// Date last modified: 2021.6.27


version 	15.0
clear 		all

// cd ""
// global OUT = " "


***************
* Main Graphs *
***************


* Figure 3a: Homogeneous IT vs. mixed sessions
* ---------------------------------------------------

use "master_pgg_cleaned.dta", clear

gen mixed = homo
recode mixed (1=0) (0=1)
label define mixlab 0 "Homogeneous" 1 "Mixed", modify
label values mixed mixlab

keep if (mixed == 0 & nationality == 1) | mixed == 1

ttest contribution, by(mixed)

collapse contribution, by(mixed)

gen x = _n

twoway ///
	(bar contrib x if x == 1, barwidth(0.8) bcolor(gs10)) ///
	(bar contrib x if x == 2, barwidth(0.8) bcolor(orange)) ///
	, ylab(0(1)10)  xlab(, nogrid)  ///
	xlab(1 "IT Homogeneous" 2 "Mixed") ///
	xscale(range(1 2)) ///
	xtitle("") ytitle("Mean Contribution by Group Composition and Nationality") ///
	legend(off) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	text(6.6 1 "6,70" "N = 198" "(Ses. = 33)", size(small)) ///
	text(6.15 2 "6,30" "N = 552" "(Ses. = 92)", size(small)) ///
	xsize(1) ysize(1) ///
	name(g1a, replace)
	graph export "${OUT}g1a.png", as(png) replace

	
* Figure 3b: Homogeneous sessions by nationality
* ---------------------------------------------------
	
use "master_pgg_cleaned.dta", clear

keep if homo == 1

reg contribution ib2.nationality, robust	

collapse contribution, by(nationality)
	
gen x = _n

cap drop y*
gen y1 = 7.5
replace y1 = . if x > 3 
gen y2 = 7.2
replace y2 = . if x < 2


twoway ///
	(bar contrib x if x == 1, barwidth(0.8) bcolor(gs10)) ///
	(bar contrib x if x == 2, barwidth(0.8) bcolor(red)) ///
	(bar contrib x if x == 3, barwidth(0.8) bcolor(blue%80)) ///
	(line y1 x, lcolor(gs1) lpattern(dash)) ///
	(line y2 x, lcolor(gs1) lpattern(dash)) ///
	, ylab(0(1)10)  xlab(, nogrid)  ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	xtitle("") ytitle("Mean Contribution in Homogenous Groups by Nationality") ///
	xlab(1 "IT Homogeneous" 2 "Fi Homogenous" 3 "Mc Homogenous") ///
	xscale(range(1 2)) ///
	legend(off) ///
	text(6.6 1 "6,70" "N = 198" "(Ses. = 33)", size(small)) ///
	text(6.55 2 "6,70" "N = 72" "(Ses. = 12)", size(small)) ///
	text(5.32 3 "5,50" "N = 72" "(Ses. = 12)", size(small)) ///
	text(7.6 2 "**", size(small)) ///
	text(7.3 2.5 "*", size(small)) ///
	xsize(1) ysize(1) ///
	name(g1b, replace)
	graph export "${OUT}g1b.png", as(png) replace	
	

* Figure 3c: Homogeneous sessions averaged vs. mixed
* ---------------------------------------------------

use "master_pgg_cleaned.dta", clear
	
gen mixed = homo
recode mixed (1=0) (0=1)
label define mixlab 0 "Homogeneous" 1 "Mixed", modify
label values mixed mixlab


ttest contribution, by(mixed)

collapse contribution, by(mixed)

gen x = _n

cap drop y*
gen y1 = 7.5
replace y1 = . if x > 2 

twoway ///
	(bar contrib x if x == 1, barwidth(0.8) bcolor(sienna)) ///
	(bar contrib x if x == 2, barwidth(0.8) bcolor(orange)) ///
	, ylab(0(1)10)  xlab(, nogrid)  ///
	xlab(1 "All Homogeneous (pooled)" 2 "Mixed") ///
	xscale(range(1 2)) ///
	xtitle("") ytitle("Mean Contribution by Group Composition") ///
	legend(off) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	text(6.3 1 "6,45" "N = 342" "(Ses. = 57)", size(small)) ///
	text(6.15 2 "6,30" "N = 552" "(Ses. = 92)", size(small)) ///
	xsize(1) ysize(1) ///
	name(g1a, replace)
	graph export "${OUT}g1c.png", as(png) replace	
		
	
* Figure 4a: Homogeneous IT vs. mixed IT sessions
* ---------------------------------------------------

use "master_pgg_cleaned.dta", clear

gen mixed = homo
recode mixed (1=0) (0=1)
label define mixlab 0 "Homogeneous" 1 "Mixed", modify
label values mixed mixlab

keep if nationality == 1

collapse contribution, by(mixed)

gen x = _n
recode x (2 = 1) (1 = 2)

twoway ///
	(bar contrib x if x == 1, barwidth(0.8) bcolor(gs10%50)) ///
	(bar contrib x if x == 2, barwidth(0.8) bcolor(gs10)) ///
	, ylab(0(1)10)  xlab(, nogrid) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	xtitle("") ytitle("Mean Contribution by Group Composition: Italians") ///
	xlab("") ///
	legend(pos(1) ring(0) order(1 "Mixed" 2 "Homogenous")) ///
	text(6.5 1 "6,50" "N = 363" "(Ses. = 92)", size(small)) ///
	text(6.6 2 "6,70" "N = 198" "(Ses. = 33)", size(small)) ///
	xsize(1) ysize(1) ///
	name(git, replace)
graph export "${OUT}git.png", as(png) replace


* Figure 4b: Homogeneous MC vs. mixed MC sessions
* ---------------------------------------------------

use "master_pgg_cleaned.dta", clear

gen mixed = homo
recode mixed (1=0) (0=1)
label define mixlab 0 "Homogeneous" 1 "Mixed", modify
label values mixed mixlab

keep if nationality == 3

collapse contribution, by(mixed)

gen x = _n
recode x (2 = 1) (1 = 2)

twoway ///
	(bar contrib x if x == 1, barwidth(0.8) bcolor(blue%50)) ///
	(bar contrib x if x == 2, barwidth(0.8) bcolor(blue%90)) ///
	, ylab(0(1)10)  xlab(, nogrid) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	xtitle("") ytitle("Mean Contribution by Group Composition: Moroccans") ///
	xlab("") ///
	legend(pos(1) ring(0) order(1 "Mixed" 2 "Homogenous")) ///
	text(5.48 1 "5,60" "N = 121" "(Ses. = 58)", size(small)) ///
	text(5.32 2 "5,50" "N = 72" "(Ses. = 12)", size(small)) ///
	xsize(1) ysize(1) ///
	name(g_mc, replace)
graph export "${OUT}gmc.png", as(png) replace

* Figure 4c: Homogeneous Fi vs. mixed Fi sessions
* ---------------------------------------------------

use "master_pgg_cleaned.dta", clear

gen mixed = homo
recode mixed (1=0) (0=1)
label define mixlab 0 "Homogeneous" 1 "Mixed", modify
label values mixed mixlab

keep if nationality == 2

ttest contribution, by(mixed)

collapse contribution, by(mixed)

gen x = _n
recode x (2 = 1) (1 = 2)

cap drop y*
gen y1 = 7.3
replace y1 = . if x > 2 

twoway ///
	(bar contrib x if x == 1, barwidth(0.8) bcolor(red%50)) ///
	(bar contrib x if x == 2, barwidth(0.8) bcolor(red)) ///
	(line y1 x, lcolor(gs1)) ///
	, ylab(0(1)10)  xlab(, nogrid) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	xtitle("") ytitle("Mean Contribution by Group Composition: Filipinos") ///
	xlab("") ///
	legend(pos(1) ring(0) order(1 "Mixed" 2 "Homogenous")) ///
	text(5.6 1 "5,70" "N = 68" "(Ses. = 34)", size(small)) ///
	text(6.55 2 "6,70" "N = 72" "(Ses. = 12)", size(small)) ///
	text(7.5 1.5 "*", size(small)) ///
	xsize(1) ysize(1) ///
	name(g_fi, replace)
graph export "${OUT}gfi.png", as(png) replace


****************************
* INTEGRATION Analysis
****************************

* Figure 5: Contributions by Employment Status Natives vs. Immigrants
* --------------------------------------------------------------
use "master_pgg_cleaned.dta", clear

preserve
collapse contrib, by(int_employ)
gen x = _n
recode x (2=1) (1=2) (3=4) (4=3)

//stuff for the line
cap drop y*
gen y1 = 7.1
replace y1 = . if x == 1
gen y2 = 6.7
replace y2 =. if x == 2
gen y3 = 7.5
replace y2 =. if x == 1


twoway (bar contrib x if x == 1, color(gs10) barw(0.5)   lwidth(thin) lcolor(black) ) ///
	(bar contrib x if x == 2, color(gs12) barw(0.5) lwidth(thin) lcolor(black) ) ///
	(bar contrib x if x == 3, color(magenta) barw(0.5)   lwidth(thin) lcolor(black) ) ///
	(bar contrib x if x == 4, color(lavender) barw(0.5)   lwidth(thin) lcolor(black) ) ///
	(line y1 x, lcolor(gs1)) ///
	(line y2 x, lcolor(gs1)) ///
	(line y3 x, lcolor(gs1)) ///
	, ylab(0(1)10) xlab(, nogrid) ///
	legend(off) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///	
	xtitle("") ytitle("Mean contribution in PGG") ///
	xlab(2 "IT not employed" 1 "IT employed" 3 "IMM employed" 4 "IMM not employed", labsize(small) angle (25)) ///
	text(6.2  2 "N = 166", size(small)) ///
	text(6.5 1  "N = 395", size(small)) ///
	text(5.3 4 "N = 202", size(small)) ///
	text(6.0 3  "N = 131", size(small)) ///
	text(6.8 3.5 "*", size(small))  ///
	text(7.6 2.5 "***", size(small)) ///
	text(7.2 3 "**", size(small)) ///
	name(emplo1, replace)
	graph export "${OUT}employ.png", as(png) replace
restore



* Figure 6: Contributions by Integration Level of Immigrants
* --------------------------------------------------------------

matrix define A = J(8, 2, 0)
matrix colnames A  = "beta" "se"
matrix rownames A = "citizen" "non citizen" "fluent" "non fluent" "friends" "no friends" "acquaintances" "no acquaintances"

* citizenship
*******************
use "master_pgg_cleaned.dta", clear

fre citizenship 
replace citizenship = . if nationality == 1 // coding Italians as Italian Citizens

gen temp_citizen = citizenship // 15 Fi and 17 Mc did not answer the citizenship question, missing
replace temp_citizen = 0 if nationality == 1
tab temp_citizen
recode temp_citizen (1 = 0) (2 = 1) (0 = 2)
label define tclab 0 "Non-Citizen" 1 "Citizen" 2 "Native Italian", modify
label values temp_citizen tclab
fre temp_citizen


reg contrib ib2.temp_c, robust
matrix B = r(table)

matrix A[1,1] = B[1,2]
matrix A[2,1] = B[1,1]
matrix A[1,2] = B[2,2]
matrix A[2,2] = B[2,1]

*language fluency
*******************
fre fluency
replace fluency = 2 if fluency == . // coding Italians as Native Italians
fre fluency


reg contrib ib2.fluency, robust
matrix B = r(table)

matrix A[3,1] = B[1,2]
matrix A[4,1] = B[1,1]
matrix A[3,2] = B[2,2]
matrix A[4,2] = B[2,1]

* friends
*******************
fre friendsit_dummy
replace friendsit_dummy = 2 if nationality == 1
tab friendsit_dummy

reg contrib ib2.friendsit_dummy, robust
matrix B = r(table)

matrix A[5,1] = B[1,2]
matrix A[6,1] = B[1,1]
matrix A[5,2] = B[2,2]
matrix A[6,2] = B[2,1]


* acquaintances
*******************
tab aquaintit_dummy
replace aquaintit_dummy = 2 if nationality == 1
tab aquaintit_dummy

reg contrib ib2.aquaintit_dummy, robust
matrix B = r(table)

matrix A[7,1] = B[1,2]
matrix A[8,1] = B[1,1]
matrix A[7,2] = B[2,2]
matrix A[8,2] = B[2,1]

* graphing coefplot
*******************
clear
svmat A, names(col)

cap drop y
gen y = 1 in 8
replace y = 2 in 7
replace y = 4 in 6
replace y = 5 in 5
replace y = 7 in 4
replace y = 8 in 3
replace y = 9 in 2 
replace y = 10 in 1

gen hi = beta + 1.96*se
gen lo = beta - 1.96*se

twoway ///
	(scatter y beta if y == 1, mcolor(maroon)) ///
	(scatter y beta if y == 2, mcolor(maroon)) ///
	(scatter y beta if y == 4, mcolor(navy)) ///
	(scatter y beta if y == 5, mcolor(navy)) ///
	(scatter y beta if y == 7, mcolor(dkorange)) ///
	(scatter y beta if y == 8, mcolor(dkorange)) ///
	(scatter y beta if y == 9, mcolor(gs9)) ///
	(scatter y beta if y == 10, mcolor(gs9)) ///
	(rcap hi lo y if y == 1, horizontal msize(vtiny)  lcolor(maroon) ) ///
	(rcap hi lo y if y == 2, horizontal msize(vtiny)  lcolor(maroon) lpattern(dash) ) ///
	(rcap hi lo y if y == 4, horizontal msize(vtiny)  lcolor(navy) ) ///
	(rcap hi lo y if y == 5, horizontal msize(vtiny)  lcolor(navy) lpattern(dash) ) ///
	(rcap hi lo y if y == 7, horizontal msize(vtiny) lcolor(dkorange)) ///
	(rcap hi lo y if y == 8, horizontal msize(vtiny)  lcolor(dkorange) lpattern(dash) ) ///
	(rcap hi lo y if y == 9, horizontal msize(vtiny)  lcolor(gs9)) ///
	(rcap hi lo y if y == 10, horizontal msize(vtiny) lcolor(gs9) lpattern(dash) ) ///
	, legend(off) ///
	scheme(538bw) ///
	plotregion(color(white) icolor(white)) ///
	xline(0, lcolor(red) lpattern(solid)) ///
	yscale(range(0 12)) ///
	ylab(1 "<10 IT acquaintances" 2 "10+ IT acquaintances" 4 "<5 IT friends" 5 "5+ IT friends" 7 "Non-Fluent" 8 "Fluent" 9 "Non-Citizen" 10 "Citizen", nogrid) ///
	ytitle("") xtitle("Difference from Natives") ///
	xsize(1) ysize(1)  
graph export "${OUT}coefplot_integration.png", as(png) replace



********************************
*  Appendix *
********************************


** Summary Statistics
*********************
use "master_pgg_cleaned.dta", clear

* making the table
* ----------------
matrix define A = J(13, 15, 0)

//italians
local i = 0
foreach var of varlist age male_dummy deduc1 deduc2 deduc3 deduc4 pggcorrect knowing_dummy employment {
	local i = `i' + 1 
	qui su `var'  if nationality == 1
	matrix A[`i', 1] = `r(mean)'
	matrix A[`i', 2] = `r(sd)'
	matrix A[`i', 3] = `r(min)'
	matrix A[`i', 4] = `r(max)'	
	matrix A[`i', 5] = `r(N)'
}

// filipino
local i = 0
foreach var of varlist age male_dummy deduc1 deduc2 deduc3 deduc4 pggcorrect knowing_dummy employment fluency citizen friendsit_dummy aquaintit_dummy {
	local i = `i' + 1 
	qui su `var'  if nationality == 2
	matrix A[`i', 6] = `r(mean)'
	matrix A[`i', 7] = `r(sd)'
	matrix A[`i', 8] = `r(min)'
	matrix A[`i', 9] = `r(max)'	
	matrix A[`i', 10] = `r(N)'
}

// moroccans
local i = 0
foreach var of varlist age male_dummy deduc1 deduc2 deduc3 deduc4 pggcorrect knowing_dummy employment fluency citizen friendsit_dummy aquaintit_dummy {
	local i = `i' + 1 
	qui su `var'  if nationality == 3
	matrix A[`i', 11] = `r(mean)'
	matrix A[`i', 12] = `r(sd)'
	matrix A[`i', 13] = `r(min)'
	matrix A[`i', 14] = `r(max)'	
	matrix A[`i', 15] = `r(N)'
}

svmat A
keep in 1/13
keep A1-A15
format A1-A15 %12.3g
foreach var of varlist A1 A2 A3 A4 A5 {
	replace `var' = . in 10 / 13
}
cap drop A0
gen A0 = ""
replace A0 = "Age" in 1
replace A0 = "Male" in 2
replace A0 = "Primary Educ." in 3
replace A0 = "Middle Educ." in 4
replace A0 = "High school/vocational Educ." in 5
replace A0 = "University" in 6
replace A0 = "Num. PGG Control Questions Correct" in 7
replace A0 = "Know another participant?" in 8
replace A0 = "Employed" in 9
replace A0 = "Fluent in Italian" in 10
replace A0 = "Italian citizen" in 11
replace A0 = "More than 5 Italian Friends" in 12
replace A0 = "More than 10 Italian Acquaintances" in 13
order A0, first

export excel using "${OUT}sumstat.xls", replace

** Balance Table 
*******************
use "master_pgg_cleaned.dta", clear

matrix A = J(27, 5, 0)
matrix colnames A = "IT" "FI" "MC" "ITvFI" "ITvMC"

//all groups: homo vs mixed 
forvalues n = 1 / 3 {

	ttest age if nationality == `n', by(homo)
	matrix A[1,`n'] = r(mu_2)
	matrix A[10,`n'] = r(mu_1)
	matrix A[19,`n'] = r(p)
	
	local i = 1
	local j = 10
	local k = 19
	foreach var of varlist male_dummy deduc1 deduc2 deduc3 deduc4 knowing_dummy employment  {
		local i = `i' + 1
		local j = `j' + 1
		local k = `k' + 1
		qui prtest `var' if nationality == `n', by(homo) 
		matrix A[`i',`n'] = r(P2)
		matrix A[`j',`n'] = r(P1)
		matrix A[`k',`n'] = r(p)
	}
	
	qui ttest pggcorrect if nationality == `n', by(homo)
	matrix A[9,`n'] = r(mu_2)
	matrix A[18,`n'] = r(mu_1)
	matrix A[27,`n'] = r(p)

}

// italians vs. filipino in homo groups
qui ttest age if nationality != 3 & homo == 1, by(nationality)
matrix A[1,4] = r(p)

local i = 1
foreach var of varlist male_dummy deduc1 deduc2 deduc3 deduc4 knowing_dummy employment  {
	local i = `i' + 1
	qui prtest `var' if nationality != 3 & homo == 1, by(nationality) 
	matrix A[`i',4] = r(p)
}

qui ttest pggcorrect if nationality != 3 & homo == 1, by(nationality)
matrix A[9,4] = r(p)


// italians vs. filipino in mixed groups
qui ttest age if nationality != 3 & homo == 0, by(nationality)
matrix A[10,4] = r(p)

local i = 10
foreach var of varlist male_dummy deduc1 deduc2 deduc3 deduc4 knowing_dummy employment  {
	local i = `i' + 1
	qui prtest `var' if nationality != 3 & homo == 0, by(nationality) 
	matrix A[`i',4] = r(p)
}

qui ttest pggcorrect if nationality != 3 & homo == 0, by(nationality)
matrix A[18,4] = r(p)


// italians vs. moroccans in homo groups
qui ttest age if nationality != 2 & homo == 1, by(nationality)
matrix A[1,5] = r(p)

local i = 1
foreach var of varlist male_dummy deduc1 deduc2 deduc3 deduc4 knowing_dummy employment  {
	local i = `i' + 1
	qui prtest `var' if nationality != 2 & homo == 1, by(nationality) 
	matrix A[`i',5] = r(p)
}

qui ttest pggcorrect if nationality != 2 & homo == 1, by(nationality)
matrix A[9,5] = r(p)


// italians vs. moroccans in mixed
qui ttest age if nationality != 2 & homo == 0, by(nationality)
matrix A[10,5] = r(p)

local i = 10
foreach var of varlist male_dummy deduc1 deduc2 deduc3 deduc4 knowing_dummy employment  {
	local i = `i' + 1
	qui prtest `var' if nationality != 2 & homo == 0, by(nationality) 
	matrix A[`i',5] = r(p)
}

qui ttest pggcorrect if nationality != 2 & homo == 0, by(nationality)
matrix A[18,5] = r(p)


svmat A
keep in 1/27
keep A1-A5
format A1-A5 %12.3f
foreach var of varlist A4 A5 {
	replace `var' = . in 19 / 27
}

gen temp1 = _n
gen temp2 = mod(temp1, 9)
recode temp2 (0 = 9)

cap drop A0
gen A0 = ""
replace A0 = "Age" if temp2 == 1
replace A0 = "Male" if temp2 == 2
replace A0 = "Primary Educ." if temp2 == 3
replace A0 = "Middle Educ." if temp2 == 4
replace A0 = "High school/vocational Educ." if temp2 == 5
replace A0 = "University" if temp2 == 6
replace A0 = "Know another participant?" if temp2 == 7
replace A0 = "Employed" if temp2 == 8
replace A0 = "Num. PGG Control Questions Correct" if temp2 == 9

order A0, first

export excel A0-A5 using "${OUT}balance.xls", replace 

**************************************
** Tables for Main Analysis 
**************************************

* Table 5 for Fig 3a: IT Homogeneous vs. Mixed Sessions
****************************************************************************
use "master_pgg_cleaned.dta", clear

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}

drop if homo==1 & nationality!=1

estimates clear
eststo: reg contrib i.homo, robust
eststo: reg contrib i.homo ${controls0}, robust	
eststo: reg contrib i.homo ${controls1}, robust	

esttab est*
esttab est* using "${OUT}tab5.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(1.homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	keep(1.homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	coeflabels(1.homo "Homogenous IT Group Composition" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress

	
* Table 6 for Fig 3b: Contributions by Nationality in Homogeneous Sessions
****************************************************************************	
use "master_pgg_cleaned.dta", clear

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}

drop if homo==0 // we only compare homogeneous sessions

estimates clear
eststo: reg contrib i.nationality, robust	
eststo: reg contrib i.nationality ${controls0}, robust	
eststo: reg contrib i.nationality ${controls1}, robust	
eststo: reg contrib ib3.nationality, robust	
eststo: reg contrib ib3.nationality ${controls0}, robust	
eststo: reg contrib ib3.nationality ${controls1}, robust	

esttab est*
esttab est* using "${OUT}tab6.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(1.nationality 2.nationality 3.nationality age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	keep(1.nationality 2.nationality 3.nationality age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	coeflabels(1.nationality "Italian" 2.nationality "Filipino" 3.nationality "Moroccan" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress

* Table 7 for Fig 3c: All Homogeneous vs. Mixed Sessions
*******************************************************************************	
use "master_pgg_cleaned.dta", clear

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}

estimates clear
eststo: reg contrib i.homo, robust
eststo: reg contrib i.homo ${controls0}, robust	
eststo: reg contrib i.homo ${controls1}, robust	

esttab est*
esttab est* using "${OUT}tab7.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(1.homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	keep(1.homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	coeflabels(1.homo "All Homogeneous Group Compositions" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress

	
* Table 8 for Fig 4a+4b+4c: Contributions by Nationality and Group Composition
*******************************************************************************
use "master_pgg_cleaned.dta", clear

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}

	
estimates clear
eststo: reg contrib i.homo if nationality == 1, robust // it
eststo: reg contrib i.homo ${controls0} if nationality == 1, robust	//it 
eststo: reg contrib i.homo ${controls1} if nationality == 1, robust	//it 
eststo: reg contrib i.homo if nationality == 2, robust // fi
eststo: reg contrib i.homo ${controls0} if nationality == 2, robust	//fi 
eststo: reg contrib i.homo ${controls1} if nationality == 2, robust	//fi 
eststo: reg contrib i.homo if nationality == 3, robust // mc
eststo: reg contrib i.homo ${controls0} if nationality == 3, robust //mc
eststo: reg contrib i.homo ${controls1} if nationality == 3, robust //mc

	
esttab est* 
esttab est* using "${OUT}tab8.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(1.homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	keep(1.homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	coeflabels(1.homo "Homogeneous Group Composition" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	

****************************	
* Table 9: Do IT react differently to MC vs. Fi?
****************************

// mixed session averages for IT by group composition
use "master_pgg_cleaned.dta", clear
								   
*generate new control  variable: gender of  immigrant men in group
gen tocount = (male ==2 & nationality != 1) 
egen imen = total(tocount), by(session_config)
tab imen // between 0 and 3 immigrant men

keep if homo == 0  //mixed sessions only 
keep if nationality == 1 // only IT, N =363
tab nationality imen // N=139 with 0, N=92 with 1, N=105 with 2, N=27 with 3

tab type_session // 2 fimixed, 5 mcmixed
tab imen type_session
encode session_type, gen(type)

keep if type ==1 | type == 3 // only sessions with 2 immigrants for a clean comparison 

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}
	
estimates clear
eststo: reg contrib i.type, robust 
eststo: reg contrib i.type ${controls0}, robust	
eststo: reg contrib i.type ${controls1}, robust	
eststo: reg contrib i.type ${controls1} i.imen, robust	
eststo: reg contrib i.type ${controls1} type##imen, robust

	
esttab est* 
esttab est* using "${OUT}tab9.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(3.type age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone 1.imen 2.imen 3.type#1.imen 3.type#2.imen  _cons) ///
	keep(3.type age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone 1.imen 2.imen 3.type#1.imen 3.type#2.imen _cons) ///
	coeflabels(3.type "Moroccan Mixed Group Composition" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study" 1.imen "1 male immigrant" 2.imen "2 male immigrants" 3.type#1.imen "1 Moroccan male" 3.type#2.imen "2 Moroccan male"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress		
	
	
**************************************
** Integration Sub-Analysis 
**************************************

********************************************************************************
* Table 10: Contributions by Employment Status for Italians and Immigrants 
*********************************************************************************
use "master_pgg_cleaned.dta", clear

fre homo 

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}

estimates clear
eststo: reg contrib ib2.int_employ homo, robust
eststo: reg contrib ib2.int_employ ${controls0} homo, robust
eststo: reg contrib ib2.int_employ ${controls1} homo, robust


esttab est*  
esttab est* using "${OUT}tab10.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(0.int_employ 1.int_employ 3.int_employ homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	keep( 0.int_employ 1.int_employ  3.int_employ homo age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	coeflabels( 0.int_employ "IT not employed" 1.int_employ "IT employed" 3.int_employ "IMM employed" ///
	homo "Homogeneous Group Composition" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study"  _cons "Constant") ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	

********************************************************************************
* Table 11: Contributions of Immigrants by Level of Integration
********************************************************************************

use "master_pgg_cleaned.dta", clear

keep if nationality !=1 // exluding Italians here, the comparison other than in the coefplot is among immigrants only

estimates clear

* citizenship
*******************
tab citizen 

eststo: reg contrib i.citizen homo, robust
estimates store citizenship


*language fluency
*******************

tab fluency

eststo: reg contrib ib2.fluency homo, robust
estimates store fluency


* friends
*******************
tab friendsit_dummy

eststo: reg contrib ib2.friendsit_dummy homo, robust
estimates store friends

* acquaintances
*******************
tab aquaintit_dummy

eststo: reg contrib ib2.aquaintit_dummy homo, robust
estimates store aquaintit

esttab est*
esttab citizenship fluency friends aquaintit using "${OUT}tab11.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(1.citizen  0.fluency  0.friendsit_dummy 0.aquaintit_dummy homo _cons) ///
	keep(1.citizen 0.fluency 0.friendsit_dummy  0.aquaintit_dummy homo _cons) ///
	coeflabels( 1.citizen "No IT Citizenship"  0.fluency "No Fluency in Italian" ///
	0.friendsit_dummy "Fewer than 5 IT friends" 0.aquaintit_dummy "Fewer than 10 IT acquaintances" homo "Homogeneous Group Composition") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	
	
***************************************************************************************
* Table 12:  Contributions by Moroccan Immigrant share in Mixed Moroccan-Italian Groups 
***************************************************************************************

use "master_pgg_cleaned.dta", clear

fre type_session
encode session_t, gen(type)
 drop if type == 1 | type == 2 | type ==3 |type == 4
fre type // ONLY 9 sessions only with one Moroccan  participant

global controls0 = "age i.male"
	su ${controls0}
global controls1 = "age i.male ib3.educ pggcorrect ib2.knowingsomeone"
	su ${controls1}

estimates clear
eststo: reg contribution ib6.type i.nationality, robust
eststo: reg contribution ib6.type i.nationality ${controls0}, robust
eststo: reg contribution ib6.type i.nationality ${controls1}, robust

esttab est*  
esttab est* using "${OUT}tab12.tex", replace ///
	b(%8.3f) se(%8.3f) ///
	star(+ 0.10 * 0.05 ** 0.01 *** 0.001) ///
	order(5.type 7.type 3.nationality age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	keep(5.type 7.type 3.nationality age 2.male 1.education 2.education 4.education pggcorrect 1.knowingsomeone  _cons) ///
	coeflabels(5.type "Mc1mixed" 7.type "MC3mixed" 3.nationality "Moroccan" age "Age" 2.male "Male" 1.education "Primary School" 2.education "Middle School" 4.education "University" pggcorrect "Game Understanding" 1.knowingsomeone "Knowing s.o. who previously participated in the study"  _cons "Constant") ///
	nodepvars nomtitles nonotes ///
	nolines posthead(\midrule) prefoot(\midrule) postfoot(\bottomrule \end{tabular}}) ///
	tex compress	


log close
exit

